
Option Strict On : Option Explicit On : Option Compare Binary : Option Infer On

Imports System
Imports System.Drawing


Namespace Code.Coloriser

    ''' <summary>
    ''' Provides Shared methods that provide the default code colorisers for different languages
    ''' </summary>
    ''' <remarks>
    ''' 'TODO:  *Theoretically* this should be plug-in extensible, however there is no practical need
    '''  If needed, the defaults could be  determined by via a config file entry, where the language
    '''  name is a lookup in the config file, and the type in that entry implements IColorTokenProvider.
    '''  Should other languages get with the snippet program, and/or folks want to provide their own
    '''  code coloriser for a given language, then we should look at doing this
    ''' </remarks>

    Public NotInheritable Class Coloriser

        Private Sub New()
            ' all members of the class are shared
        End Sub


#Region "default colors"

        ''' <summary>
        ''' Get the default color of the code element
        ''' </summary>
        ''' <param name="element"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function CodeColor(Optional ByVal element As CodeElement = CodeElement.NormalCode) As Color
            Select Case element
                Case CodeElement.NormalCode
                    Return Color.Black
                Case CodeElement.Keyword
                    Return Color.Blue
                Case CodeElement.Preprocessor
                    Return Color.Blue
                Case CodeElement.StringOrChar
                    Return Color.DarkRed
                Case CodeElement.Comment
                    Return Color.Green
                Case Else
                    Return Color.Black
            End Select
        End Function

#End Region


#Region "default colorisers"

        Private Shared m_VBColoriser As VBCodeColoriser

        Public Shared ReadOnly Property VBColoriser() As IColorTokenProvider
            Get
                If m_VBColoriser Is Nothing Then
                    m_VBColoriser = New VBCodeColoriser
                End If
                Return m_VBColoriser
            End Get
        End Property


        Private Shared m_CSharpColoriser As CSharpCodeColoriser

        Public Shared ReadOnly Property CSharpColoriser() As IColorTokenProvider
            Get
                If m_CSharpColoriser Is Nothing Then
                    m_CSharpColoriser = New CSharpCodeColoriser
                End If
                Return m_CSharpColoriser
            End Get
        End Property


        Private Shared m_JSharpColoriser As JSharpCodeColoriser

        Public Shared ReadOnly Property JSharpColoriser() As IColorTokenProvider
            Get
                If m_JSharpColoriser Is Nothing Then
                    m_JSharpColoriser = New JSharpCodeColoriser
                End If
                Return m_JSharpColoriser
            End Get
        End Property


        Private Shared m_JavaColoriser As JavaCodeColoriser

        Public Shared ReadOnly Property JavaColoriser() As IColorTokenProvider
            Get
                If m_JavaColoriser Is Nothing Then
                    m_JavaColoriser = New JavaCodeColoriser
                End If
                Return m_JavaColoriser
            End Get
        End Property


        Private Shared m_JavascriptColoriser As JavascriptCodeColoriser

        Public Shared ReadOnly Property JavascriptColoriser() As IColorTokenProvider
            Get
                If m_JavascriptColoriser Is Nothing Then
                    m_JavascriptColoriser = New JavascriptCodeColoriser
                End If
                Return m_JavascriptColoriser
            End Get
        End Property


        Private Shared m_CppColoriser As CppCodeColoriser

        Public Shared ReadOnly Property CppColoriser() As IColorTokenProvider
            Get
                If m_CppColoriser Is Nothing Then
                    m_CppColoriser = New CppCodeColoriser
                End If
                Return m_CppColoriser
            End Get
        End Property


        Private Shared m_CColoriser As CCodeColoriser

        Public Shared ReadOnly Property CColoriser() As IColorTokenProvider
            Get
                If m_CColoriser Is Nothing Then
                    m_CColoriser = New CCodeColoriser
                End If
                Return m_CColoriser
            End Get
        End Property


        Private Shared m_AsmColoriser As AsmCodeColoriser

        Public Shared ReadOnly Property AsmColoriser() As IColorTokenProvider
            Get
                If m_AsmColoriser Is Nothing Then
                    m_AsmColoriser = New AsmCodeColoriser
                End If
                Return m_AsmColoriser
            End Get
        End Property


        Private Shared m_BatColoriser As BatchCodeColoriser

        Public Shared ReadOnly Property BatColoriser() As IColorTokenProvider
            Get
                If m_BatColoriser Is Nothing Then
                    m_BatColoriser = New BatchCodeColoriser
                End If
                Return m_BatColoriser
            End Get
        End Property


        Private Shared m_XmlColoriser As XmlCodeColoriser

        Public Shared ReadOnly Property XmlColoriser() As IColorTokenProvider
            Get
                If m_XmlColoriser Is Nothing Then
                    m_XmlColoriser = New XmlCodeColoriser
                End If
                Return m_XmlColoriser
            End Get
        End Property


        Private Shared m_SQLColoriser As SQLCodeColoriser

        Public Shared ReadOnly Property SQLColoriser() As IColorTokenProvider
            Get
                If m_SQLColoriser Is Nothing Then
                    m_SQLColoriser = New SQLCodeColoriser
                End If
                Return m_SQLColoriser
            End Get
        End Property


        Private Shared m_MshColoriser As MshCodeColoriser

        Public Shared ReadOnly Property MshColoriser() As IColorTokenProvider
            Get
                If m_MshColoriser Is Nothing Then
                    m_MshColoriser = New MshCodeColoriser
                End If
                Return m_MshColoriser
            End Get
        End Property


        Private Shared m_UnknownColoriser As UnknownCodeColoriser

        Public Shared ReadOnly Property UnknownColoriser() As IColorTokenProvider
            Get
                If m_UnknownColoriser Is Nothing Then
                    m_UnknownColoriser = New UnknownCodeColoriser
                End If
                Return m_UnknownColoriser
            End Get
        End Property

#End Region


        Public Shared Function GetColoriser(ByVal language As String) As IColorTokenProvider
            Select Case language.ToLower

                Case "vb", "visual basic"
                    Return VBColoriser

                Case "csharp", "c#"
                    Return CSharpColoriser

                Case "jsharp", "j#"
                    Return JSharpColoriser

                Case "java"
                    Return JavaColoriser

                Case "javascript", "js"
                    Return JavascriptColoriser

                Case "cpp", "c++"
                    Return CppColoriser

                Case "c"
                    Return CColoriser

                Case "htm", "html", "shtm", "shtml", "xml", "xsl", "manifest"
                    Return XmlColoriser

                Case "asm", "assembly"
                    Return AsmColoriser

                Case "bat", "batch"
                    Return BatColoriser

                Case "sql"
                    Return SQLColoriser

                Case "msh"
                    Return MshColoriser

                Case Else
                    Return UnknownColoriser
            End Select
        End Function


        Public Shared Function GetColoriser(ByVal language As CodeLanguage) As IColorTokenProvider
            Select Case language

                Case CodeLanguage.VB
                    Return VBColoriser

                Case CodeLanguage.CSharp
                    Return CSharpColoriser

                Case CodeLanguage.JSharp
                    Return JSharpColoriser

                Case CodeLanguage.Cpp
                    Return CppColoriser

                Case CodeLanguage.C
                    Return CColoriser

                Case CodeLanguage.Java
                    Return JavaColoriser

                Case CodeLanguage.Javascript
                    Return JavascriptColoriser

                Case CodeLanguage.XML
                    Return XmlColoriser

                Case CodeLanguage.Asm
                    Return AsmColoriser

                Case CodeLanguage.Batch
                    Return BatColoriser

                Case CodeLanguage.SQL
                    Return SQLColoriser

                Case CodeLanguage.Msh
                    Return MshColoriser

                Case CodeLanguage.Unknown
                    Return UnknownColoriser

                Case Else
                    Return UnknownColoriser
            End Select
        End Function

    End Class

End Namespace


